package queue_stack.leetcode.easy;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Queue;

/**
 * @author bruin_du
 * @description 用两个栈实现队列
 * @date 2022/5/16 0:02
 **/
public class Offer09_CQueue {
    private Deque<Integer> stack1;
    private Deque<Integer> stack2;
    public Offer09_CQueue() {
        stack1 = new ArrayDeque<>();
        stack2 = new ArrayDeque<>();
    }

    public void appendTail(int value) {
        stack1.offerLast(value);
    }

    public int deleteHead() {
        if(!stack2.isEmpty()){
            return stack2.pollLast();
        }
        if(stack1.isEmpty()){
            return -1;
        }else {
            while (!stack1.isEmpty())
                stack2.offerLast(stack1.pollLast());
            return stack2.pollLast();
        }
    }
}
